package com.example.laserharp1;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class FunctionPage extends AppCompatActivity {

    TextView ipaddress, device;
    Button volume, key, instrument, back,home;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_function_page);

        initialWork();              // device and ip
        exqListener();              // jump to "Volume" "Key" "Instrument" "Back" "Home"
    }

    private void initialWork(){
        ipaddress = findViewById(R.id.IPAddress);
        device = findViewById(R.id.device);
        volume = findViewById(R.id.volume);
        key = findViewById(R.id.key);
        instrument = findViewById(R.id.instrument);
        back = findViewById(R.id.back);
        home = findViewById(R.id.home);

        if (GlobalVariable.ip != null) {
            ipaddress.setText("Target IP: " + GlobalVariable.ip);
        } else {
            ipaddress.setText("NONE");
        }

        if (GlobalVariable.device != null) {
            device.setText("Target Device: " + GlobalVariable.device);
        } else {
            device.setText("Not Connected");
        }
    }

    private void exqListener(){
        volume.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(FunctionPage.this,Volume.class);
                startActivity(intent);
            }
        });
        key.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent intent = new Intent(FunctionPage.this,Key.class);
                startActivity(intent);
            }
        });
        instrument.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent intent = new Intent(FunctionPage.this,Instrument.class);
                startActivity(intent);
            }
        });
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent intent = new Intent(FunctionPage.this,MainActivity.class);
                startActivity(intent);
            }
        });
        home.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent intent = new Intent(FunctionPage.this,MainActivity.class);
                startActivity(intent);
            }
        });
    }
}
